import 'package:flutter/material.dart';
import 'package:slwl/pages/login/index.dart';
import 'package:slwl/utils/token.dart';

class SettingPage extends StatelessWidget {
  const SettingPage({super.key});

  @override
  Widget build(BuildContext context) {
    List list = ['换绑手机', '修改密码', '消息通知设置', '修改密码', '清理缓存'];

    void listItemTap(int index) {
      if (index == 0) {
        print('换绑手机');
      }
    }

    List<Widget> getListItem() {
      List<Widget> item = [];
      for (var i = 0; i < list.length; i++) {
        item.add(
          GestureDetector(
            onTap: () {
              listItemTap(i);
            },
            child: Container(
              height: 60,
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Text(
                    list[i],
                    style: const TextStyle(
                      fontSize: 16,
                      color: Color(0xFF2A2929),
                    ),
                  ),
                  const Icon(
                    Icons.arrow_forward_ios,
                    size: 20,
                    color: Color(0xFF818181),
                  ),
                ],
              ),
            ),
          ),
        );
        if (i != list.length - 1) {
          item.add(const Divider(
            height: 1,
            color: Color(0xFFF4F4F4),
          ));
        }
      }
      return item;
    }

    return Scaffold(
        backgroundColor: const Color(0xFFF4F4F4),
        appBar: AppBar(
          title: const Text('系统设置'),
          backgroundColor: Colors.white,
          // 标题颜色
          titleTextStyle: const TextStyle(
            color: Colors.black,
            fontSize: 18,
          ),
          // 图标颜色
          iconTheme: const IconThemeData(
            color: Colors.black,
          ),
          leading: IconButton(
            icon: const Icon(
              Icons.arrow_back_ios,
              size: 20,
            ),
            onPressed: () {
              Navigator.pop(context);
            },
          ),
          //居中
          centerTitle: true,
        ),
        body: Container(
          padding: const EdgeInsets.only(top: 15, left: 15, right: 15),
          child: Column(
            children: [
              Container(
                padding: const EdgeInsets.only(left: 15, right: 15),
                decoration: BoxDecoration(
                  color: Colors.white,
                  borderRadius: BorderRadius.circular(8),
                ),
                child: Column(
                  children: getListItem(),
                ),
              ),
              GestureDetector(
                onTap: () {
                  TokenManager().removeToken();
                  // 退出登录后，跳转到登录页面
                  Navigator.pushReplacement(
                    context,
                    MaterialPageRoute(
                      builder: (context) => const LoginPage(),
                    ),
                  );
                },
                child: Container(
                  width: double.infinity,
                  height: 60,
                  margin: const EdgeInsets.only(top: 40),
                  alignment: Alignment.center,
                  decoration: BoxDecoration(
                    color: Colors.white,
                    borderRadius: BorderRadius.circular(8),
                  ),
                  child: const Text(
                    '退出',
                    style: TextStyle(
                      fontSize: 16,
                      color: Color(0xFF2A2929),
                    ),
                  ),
                ),
              ),
            ],
          ),
        ));
  }
}
